package logic

import (
	"community/communityrpc/communityrpc"
	"community/communityrpc/internal/svc"
	"community/models/mysqlinit"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLogic {
	return &AddCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddCommentLogic) AddComment(in *communityrpc.AddCommentRequest) (*communityrpc.AddCommentResponse, error) {
	// todo: add your logic here and delete this line
	comment := mysqlinit.Comment{

		UserId:   in.UserId,
		PostId:   in.PostId,
		CommText: in.CommText,
	}
	mysqlinit.DB.Debug().Create(&comment)

	return &communityrpc.AddCommentResponse{
		Id: int64(comment.ID),
	}, nil
}
